﻿//============================================================
//write by bxl at 2021-06-03 15:11:29
//============================================================



using System.Collections.Generic;
using System;
using BCService.Utils;
using BCCommon;
using BCData.TMS.TransferStation;
using BCDto.TMS.TransferStation;
using BCEntity.TMS.TransferStation;
using BCDto.Sim.Admin.Admin;

namespace BCService.TMS.TransferStation
{
    public class TransferStationService : ITransferStationService
    {
        #region var
        private readonly IDatabaseContext databaseContext;
        private ITransferStationData transferStationData;


        #endregion

        #region 构造函数
        public TransferStationService(ITransferStationData transferStationData, IDatabaseContext databaseContext)
        {
            this.transferStationData = transferStationData;
            this.databaseContext = databaseContext;
        }
        #endregion

        #region Add
        /// <summary>
        /// 添加新仓库中转站纪录
        /// </summary>
        /// <param name="transferStationRequestDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public TransferStationDto Add(TransferStationRequestDto transferStationRequestDto, AdminDto admin)
        {
            return transferStationData.InsertAsync(transferStationRequestDto.As<TransferStationEntity>()).GetAwaiter().GetResult().As<TransferStationDto>();
        }
        #endregion

        #region update
        /// <summary>
        /// 修改仓库中转站记录
        /// </summary>
        /// <param name="transferStationDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public TransferStationDto Update(TransferStationDto transferStationDto, AdminDto admin)
        {
            return transferStationData.UpdateAsync(transferStationDto.As<TransferStationEntity>()).GetAwaiter().GetResult().As<TransferStationDto>();

        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除仓库中转站记录
        /// </summary>
        /// <param name="transferStationId"></param>
        /// <returns></returns>
        public void Delete(long transferStationId)
        {
            transferStationData.DeleteAsync(transferStationId).GetAwaiter().GetResult();

        }
        #endregion

        #region GetByTransferStationId
        /// <summary>
        /// 获取仓库中转站记录
        /// </summary>
        /// <param name="transferStationId"></param>
        /// <returns></returns>
        public TransferStationDto GetById(long transferStationId)
        {
            var a = transferStationData.GetEntityAsync(transferStationId).GetAwaiter().GetResult();
            return a.As<TransferStationDto>();
        }
        #endregion

        #region GetList  获取仓库中转站记录--[分页]
        public PageableList<TransferStationDto> GetList(int pageIndex, int pageSize)
        {
            int fCount = 0;
            IEnumerable<TransferStationEntity> fList;

            (fList, fCount) = transferStationData.GetListAsync(pageIndex, pageSize).GetAwaiter().GetResult();

            return new PageableList<TransferStationDto>()
            {
                Count = fCount,
                Items = fList.As<IEnumerable<TransferStationDto>>(),
                PageIndex = pageIndex,
                PageSize = pageSize,
                ServerTime = DateTime.Now,
            };
        }
        #endregion
    }
}